package com.samphanie.auiu.admin.controller;

import com.samphanie.auiu.admin.service.ISysRoleMenuService;
import com.samphanie.auiu.common.utils.ApiResponse;
import com.samphanie.auiu.mbg.model.SysRoleMenu;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 角色菜单关联Controller
 *
 * @author zsy
 * @date 2021-05-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/role_menu")
public class SysRoleMenuController {
    private final ISysRoleMenuService sysRoleMenuService;

    /**
     * 查询角色菜单关联列表
     */
    @GetMapping("/list")
    public ApiResponse<?> list(@RequestParam Map<String, Object> query) {
        return ApiResponse.success(sysRoleMenuService.listPage(query));
    }

    /**
     * 获取角色菜单关联详细信息
     */
    @GetMapping(value = "/{id}")
    public ApiResponse<?> getInfo(@PathVariable("id") Long id) {
        return ApiResponse.success(sysRoleMenuService.getById(id));
    }

    /**
     * 新增角色菜单关联
     */
    @PostMapping("/add")
    public ApiResponse<?> add(@RequestBody SysRoleMenu sysRoleMenu) {
        sysRoleMenuService.save(sysRoleMenu);
        return ApiResponse.success("新增成功");
    }

    /**
     * 修改角色菜单关联
     */
    @PutMapping("update")
    public ApiResponse<?> update(@RequestBody SysRoleMenu sysRoleMenu) {
        sysRoleMenuService.updateById(sysRoleMenu);
        return ApiResponse.success("修改成功");
    }

    /**
     * 删除角色菜单关联
     */
    @DeleteMapping("/delete")
    public ApiResponse<?> remove(@RequestBody Long[] ids) {
        sysRoleMenuService.removeByIds(Arrays.asList(ids));
        return ApiResponse.success("删除成功");
    }
}
